package com.test.parse;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.test.parse.BaofenParser.BaofenVR;
import com.test.parse.BaofenParser.BaofenVRDataObj;
import com.test.parse.BaofenParser.BaofenVRVideo;

/**
 * Servlet implementation class ParseTestServlet
 */
@WebServlet("/ParseTestServlet")
public class ParseTestServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ParseTestServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		BaofenVR baofenVR = BaofenParser.parse();
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=utf-8");
		PrintWriter out = response.getWriter();
		Gson gson = new Gson();
		String html = "";
		String videoName = "";
		String videoSize = "";
		String videoResolution = "";
		String videoPlayUrl = "";
		String videoThumbnailUrl = "";
		String url;
		out.print("<html><body>");
		for (BaofenVRDataObj obj : baofenVR.data.list){
			url = obj.url;			
			BaofenVRVideo video = BaofenParser.parseFromUrl(url);
			videoName = video.data.title;
			videoSize = video.data.video_attrs.get(0).size;
			videoResolution = video.data.video_attrs.get(0).definition_name;
			videoPlayUrl = video.data.video_attrs.get(0).play_url;
			videoThumbnailUrl = obj.pic_url;
			out.print("<p>");
			out.print("<img src="+videoThumbnailUrl+"><br>");
			out.print("视频名字:"+videoName+"</br>");
			out.print("视频大小:"+videoSize+"<br>");
			out.print("视频分辨率:"+videoResolution+"<br>");
			out.print("视频播放地址:"+videoPlayUrl+"<br>");
			
			out.print("</p>");
		}
		out.print("</body></html>");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
